const app = getApp<IAppOption>();
// ts 无法重新声明块范围变量 "app"
// https://blog.csdn.net/weixin_44383533/article/details/130583892
// 经测试在任意一个页面添加就可以了，其它页面就不会报红了
export { };

const menuData = [
  {
    title: "融媒平台",
    rows: [
      // {
      //   title: '西昌门户网站',
      //   tit: '',
      //   url: '',
      //   type: 'address',
      // },
    ],
  },
  {
    title: "关于我们",
    rows: [
      // {
      //   title: '帮助中心',
      //   tit: '',
      //   url: '',
      //   type: 'help-center',
      // },
    ],
  },
];

const orderTagInfos = [
  {
    title: "我的积分",
    iconName: "wallet",
    orderNum: 0,
    tabType: 5,
    status: 1,
  },
  {
    title: "我的兑换",
    iconName: "deliver",
    orderNum: 0,
    tabType: 10,
    status: 1,
  },
  {
    title: "积分商城",
    iconName: "package",
    orderNum: 0,
    tabType: 40,
    status: 1,
  },
];

Page({
  data: {
    userInfo: {
      uid: 0,
      nickname: "",
      avatarUrl: "",
    },
    currAuthStep: 1,
    menuData,
    orderTagInfos,
    versionNo: "",
  },

  onLoad() {
    this.getVersionInfo();

    // 回调用户信息
    app.userInfoReadyCallback = (result: any) => {
      this.setData({ userInfo: result });
      this.init();
    };
  },

  onShow() {
    this.init();
  },

  init() {
    this.fetUseriInfoHandle();
  },

  fetUseriInfoHandle() {
    const { userInfo } = app.globalData as any;
    if (userInfo && userInfo.mobile) {
      if (userInfo.mobile && userInfo.nickname) {
        this.setData({ userInfo, currAuthStep: 3 });
      } else {
        this.setData({ userInfo, currAuthStep: 2 });
      }
    }
  },

  goUserEditPage() {
    const { currAuthStep } = this.data;
    if (currAuthStep === 2 || currAuthStep === 3) {
      wx.navigateTo({ url: "/pages/ucenter/person-info/index" });
    } else {
      wx.navigateTo({ url: "/pages/login/index" });
      // this.fetUseriInfoHandle();
    }
  },

  getVersionInfo() {
    const versionInfo = wx.getAccountInfoSync();
    const { version, envVersion } = versionInfo.miniProgram;
    this.setData({
      versionNo: envVersion === "release" ? version : envVersion,
    });
  },
});
